/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.iti.jets.gpts.service;

import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.UniformInterfaceException;
import com.sun.jersey.api.client.WebResource;

/**
 * Jersey REST client generated for REST resource:AuthonticationService
 * [/authontication]<br>
 * USAGE:
 * <pre>
 *        authentication client = new authentication();
 *        Object response = client.XXX(...);
 *        // do whatever with response
 *        client.close();
 * </pre>
 *
 * @author noha
 */
public class Authentication {
    private WebResource webResource;
    private Client client;
    private static final String BASE_URI = "http://localhost:48651/GPTRP/rest";

    public Authentication() {
        com.sun.jersey.api.client.config.ClientConfig config = new com.sun.jersey.api.client.config.DefaultClientConfig();
        client = Client.create(config);
        webResource = client.resource(BASE_URI).path("authontication");
    }

    
    public String login(String email, String pass) throws UniformInterfaceException {
        WebResource resource = webResource;
        if (email != null) {
            resource = resource.queryParam("email", email);
        }
        if (pass != null) {
            resource = resource.queryParam("pass", pass);
        }
        resource = resource.path("login");
        return resource.accept(javax.ws.rs.core.MediaType.TEXT_PLAIN).get(String.class);
    }

    public void close() {
        client.destroy();
    }
    
}
